﻿package org.xhs.report
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public class PreLoader extends MovieClip
    {
        protected var ld_timer_total:Number = 600;
        protected var ld_timer_fix:int = 1000;
        protected var ld:Loading;

        public function PreLoader()
        {
            stage.showDefaultContextMenu = false;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stop();
            this.createLoading();
            addEventListener(Event.ENTER_FRAME, this.checkLoaded);
            if (loaderInfo.bytesLoaded == loaderInfo.bytesTotal)
            {
                this.loadComplete();
            }
            else
            {
                loaderInfo.addEventListener(Event.COMPLETE, this.loadComplete);
                loaderInfo.addEventListener(ProgressEvent.PROGRESS, this.loadProgress);
            }
            return;
        }// end function

        protected function checkLoaded(event:Event = null) : void
        {
            if (stage.stageWidth > 0 && stage.stageHeight > 0)
            {
                removeEventListener(Event.ENTER_FRAME, this.checkLoaded);
                if (this.ld)
                {
                    this.ld.x = stage.stageWidth / 2;
                    this.ld.y = stage.stageHeight / 2;
                    addChild(this.ld);
                }
            }
            return;
        }// end function

        protected function loadProgress(event:ProgressEvent) : void
        {
            var _loc_2:* = event.bytesLoaded / event.bytesTotal;
            var _loc_3:String = this;
            var _loc_4:* = this.ld_timer_total + 1;
            _loc_3.ld_timer_total = _loc_4;
            this.ld.loadBar.width = Math.atan(this.ld_timer_total / this.ld_timer_fix) * 2 * 210 / Math.PI;
            this.ld.loadBar.scaleX = Math.min(this.ld.loadBar.scaleX, 0.8);
            if (loaderInfo.bytesLoaded == loaderInfo.bytesTotal)
            {
                this.loadComplete();
            }
            return;
        }// end function

        protected function loadComplete(event:Event = null) : void
        {
            loaderInfo.removeEventListener(Event.COMPLETE, this.loadComplete);
            loaderInfo.removeEventListener(ProgressEvent.PROGRESS, this.loadProgress);
            if (this.ld)
            {
                if (contains(this.ld))
                {
                    removeChild(this.ld);
                }
                this.ld = null;
            }
            nextFrame();
            this.initApp();
            return;
        }// end function

        protected function createLoading() : void
        {
            this.ld = new Loading();
            return;
        }// end function

        protected function initApp() : void
        {
            var _loc_2:Object = null;
            var _loc_1:* = getDefinitionByName("baidu.wenku.Main") as Class;
            if (_loc_1 != null)
            {
                _loc_2 = new _loc_1;
                addChild(_loc_2 as DisplayObject);
                _loc_2.init(this.stage);
            }
            return;
        }// end function

    }
}
